<%-- 实体通用布局过滤条件布局jsp页面 --%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/views/common/taglibs.jsp" %>
<!DOCTYPE>
<html>
<head>
	<!-- 引入通用js、css文件(xiaogq) -->
	<meta name="decorator" content="default">
	<link rel="stylesheet" type="text/css" href="${ctx}/css/widget/multiselect/multiselect.css"/>
	<link rel="stylesheet" type="text/css" href="${ctx}/css/common/operation/sys_operation.css"/>
</head>
<body>
<div class="button_list">
	<a href="javascript:;" tableCode="${entityId}" onclick="exportEntity(this)">
            <span class="span_button">
                <span><img src="${ctx}/image/common/operation/oper_EXPORT.png"></span>
                <span name="buTitle">导出</span>
            </span>
	</a>
	<a href="javascript:;" onclick="javascript:parent.closeTab();">
            <span class="span_button">
                <span><img src="${ctx}/image/common/operation/oper_CANCEL.png"></span>
                <span name="buTitle">取消</span>
            </span>
	</a>
</div>
<div class="box" style="float: left;">
	<div class="left" style="width: 240px; padding-left: 10px; line-height: 35px; background-color: rgb(92,188,228);float: left">待选</div>
	<div class="right" style="width: 240px; padding-left: 10px; line-height: 35px; background-color: rgb(85,145,225);float: right">已选</div>
	<div id="hidden_field" class="box_l">
		<c:forEach items="${leftlist}" var="item" varStatus="status">
			<li><input type="checkbox" id="check${item.id}" fieldId="${item.id}" fieldName="${item.name}" inchinese="${item.inchinese}" shareFieldId="${item.shareFieldId}" restricter="${item.restricter}" ifcascade="${item.ifcascade}" class="checkbox"><label for="check${item.id}">${item.inchinese}</label></li>
		</c:forEach>
	</div>
	<div class="box_m">
		<a href="javascript:" id="alltop">首个</a>
		<a href="javascript:" id="top"><span class="glyphicon glyphicon-chevron-up"></span></a>
		<a href="javascript:" id="allleft"><span class="glyphicon glyphicon-chevron-left"></span></a>
		<a href="javascript:" id="allright"><span class="glyphicon glyphicon-chevron-right"></span></a>
		<a href="javascript:" id="bottom"><span class="glyphicon glyphicon-chevron-down"></span></a>
		<a href="javascript:" id="allbottom">最后</a>
	</div>
	<div id="show_field" class="box_r">
		<c:forEach items="${rightlist}" var="item" varStatus="status">
			<li><input type="checkbox" id="check${item.id}" fieldId="${item.id}" fieldName="${item.name}" inchinese="${item.inchinese}" shareFieldId="${item.shareFieldId}" restricter="${item.restricter}" ifcascade="${item.ifcascade}" class="checkbox"><label for="check${item.id}">${item.inchinese}</label></li>
		</c:forEach>
	</div>
</div>
<div class="box1">
	<div class="export-header">选择导出选项</div>
	<div class="export-con">
		<input type="hidden" value="" id="entityIdVal">
		<input type="hidden" value="" id="positionVal">
		<table class="table-base" style="width:100%;">
			<tbody>
				<tr>
					<td colspan="2">请选择导出的属性以及导出文本文件的字符集。导出为Excel(*.xls)格式，列数不能超过256列。</td>
				</tr>
				<tr>
					<td style="text-align: left; width:15%" class="table-label-title">导出格式：</td>
					<td style="text-align: left; width:85%" class="table-label-edit">
						<select name="exportFileKind" id="exportFileKind" class="tb-select" onchange="javascript:funChangeExport();">
							<option value="1">Excel(*.xls)</option>
							<option value="2">Excel(*.xlsx)</option>
							<option value="3">CSV(*.csv)</option>
						</select>
					</td>
				</tr>
				<tr class="format-cvs" style="display: table-row;">
					<td width="100%" colspan="2" align="left">
						<label for="comma" class="sdialog-option">
							<input type="radio" id="comma" name="commacutup" checked="checked" style="float:left;margin-top:15px;">
							<span style="float:left;height:40px;line-height:40px;">逗号分隔的文件</span>
						</label>
					</td>
				</tr>
				<tr class="format-cvs" style="display: table-row;">
					<td style="text-align: left; width:100%" colspan="2">
						<label for="commacutup" class="sdialog-option">
							<input type="radio" id="commacutup" name="commacutup" style="float:left;margin-top:15px;">
							<span style="float:left;height:40px;line-height:40px;">自定义分隔符分隔的文件</span>
						</label>
						<input type="text" id="punctuate" name="punctuate" value="," class="tb-input" style="width:50px; float:left;margin-top:8px;">
					</td>
				</tr>
				<tr class="format-cvs" style="display: table-row;">
					<td style="text-align: left; width:15%" class="table-label-title">编码方式：</td>
					<td style="text-align: left; width:85%" class="table-label-edit">
						<select id="exportEcord" name="exportEcord" class="tb-select">
							<option value="UTF-8">Unicode (UTF8) 字符编码</option>
							<option value="GBK">GBK 汉字国标扩展码</option>
							<option value="GB2312">GB2312 简体中文字符编码</option>
						</select>
					</td>
				</tr>
			</tbody>
		</table>
	</div>
</div>
<!-- 通用导出成功提示下载模态框 -->
<div class="modal fade" id="exportModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"></div>

<script type="text/javascript" src="${ctx}/js/widget/bootstrap/bootstrap.min.js"></script>
<script type="text/javascript" src="${ctx}/js/widget/multiselect/multiselect.js"></script>
<script type="text/javascript" src="${ctx}/js/common/export/entity_export.js"></script>
<script type="text/javascript">
	$(document).ready(function(){
		//改变导入文件格式方法
		funChangeExport();
		$(".box").orso({
			boxl:".box_l",//左边大盒子
			boxr:".box_r",//右边大盒子
			boxlrX:"li",//移动小盒子
			boxon:"choose",//点击添加属性
			checkbox:".checkbox",//复选框（新添加）
			idclass:true,//添加的属性是否为class//true=class; false=id;
			boxtan:"#top",//单个向上移动按钮
			boxban:"#bottom",//单个向下移动按钮
			boxalllan:"#allleft",//批量向左移动按钮
			boxallran:"#allright",//批量向右移动按钮
			boxalltan:"#alltop",//移动第一个按钮
			boxallban:"#allbottom"//移动最后一个按钮
		});
	});

	//通用导出方法(xiaogq)
	function exportEntity(node) {
		var entityId = $(node).attr("tableCode");
		//获得导出格式(1:*.xls,2:*.xlsx,3:*.csv)
		var exportFileKind = $("#exportFileKind").val();
		var splitValue = "";//如果导出的是csv则该变量表分隔符
		//如果是导出csv格式文件
		if(exportFileKind == 3){
			var flag = $("#comma").attr('checked');
			var zdyflag = $("#commacutup").attr('checked');
			if(flag){
				splitValue = ",";
			}
			if(zdyflag){
				splitValue = $("#punctuate").val();
			}
		}
		var unicode = $("#exportEcord").val();//得到编码格式
		var json = "";
		$("#show_field li").find("input").each(function(index,domEle) {
			json = json+",{";
			json = json+'"fieldId":"'+$(domEle).attr("fieldId")+'",';
			json = json+'"fieldName":"'+$(domEle).attr("fieldName")+'",';
			json = json+'"inchinese":"'+$(domEle).attr("inchinese")+'"}';
		});
		//alert(json.substring(1));
		if(json != ""){
			//交到后台开始数据导出
			$.ajax({
				type: "post",
				url: "${ctx}/ExportImport/entityExport.do",
				data: {entityId:entityId,kind:exportFileKind,splitValue:splitValue,unicode:unicode,jsonChar:"["+json.substring(1)+"]"},
				dataType: "json",
				success: function(data) {
					var text = "导出实体数据成功：<a href='${ctx}/views/common/export/export_file_download.jsp?path="+data.path+"&name="+data.name+"' style='color:blue' >请点击下载</a> "
					exportAlert("导出提示",text);
				},
				error: function() {
					alert("数据导出时发生错误!");
				}
			});
		}else{
			alert("导出属性: 必须填写");
			return false;
		}
	}

	//改变导入文件格式方法
	function funChangeExport(){
		var exportFileKind = $("#exportFileKind").val();
		if(exportFileKind == 3){
			$(".format-cvs").show();
		}else {
			$(".format-cvs").hide();
		}
	}
</script>
</body>
</html>
